<?
    abstract class Principio_Model_Templatable
    {
        const TEMPLATE_COMMON = -1;
        const TEMPLATE_GENERAL = -2;

        const TEMPLATE_SHIFT = 2;


        private $linked_list;

        public function __construct()
        {
            $this->linked_list = null;
        }


        public function getTemplate($template_index)
        {
            return $this->linked_list->getItem(intval($template_index) + self::TEMPLATE_SHIFT)->getTemplate();
        }


        public function setTemplate($template_index, $template)
        {
            $this->linked_list->getItem(intval($template_index) + self::TEMPLATE_SHIFT)->setTemplate($template);
            return $this;
        }


        public function getTemplates()
        {
            return $this->linked_list;
        }


        // Init empty $template_count templates
        protected function initTemplates($template_count = -1)
        {
            if ($template_count == -1)
                $this->linked_list = $this->fetchTemplates();
            else
            {
                $this->linked_list = new PrincipioLab_LinkedList();

                for ($i = 0; $i <= intval($template_count) + 1; $i ++)
                    $this->linked_list->addItem(new Principio_Model_Template($i));
            };
        }


        abstract protected function fetchTemplates();
        abstract public function addTemplates();
        abstract public function saveTemplates();
        abstract public function deleteTemplates();
    }
?>